﻿using System.Collections.Generic;

namespace Viyi.Util.Collections
{
    public static class DictionaryExtention
    {
        public static DictionaryIndexer<TKey, TValue> CreateIndexer<TKey, TValue>(
            this IDictionary<TKey, TValue> source)
        {
            return new DictionaryIndexer<TKey, TValue>(source);
        }

        public static TValue GetValue<TKey, TValue>(
            this IDictionary<TKey, TValue> dict,
            TKey key,
            TValue defaultValue = default(TValue))
        {
            return dict.TryGetValue(key, out TValue value)
                ? value
                : defaultValue;
        }
    }
}
